import 'package:flutter/foundation.dart';
import 'package:star_unbounded/utils/clipboard.dart';

enum ClipboardDataType {
  text,image,nil
}


class ClipboardData with ChangeNotifier {

  ClipboardDataType type = ClipboardDataType.nil;
  late String _text;
  late Uint8List _img;

  String get text => _text;
  Uint8List get img => _img;

  set text(String s){
    _text = s;
    notifyListeners();

  }

  set img(Uint8List u8l){
    _img = u8l;
        notifyListeners();
  }

 static readText() async {
    return await Clipboard.read();
  }
  static readImg() async {
    return  await Clipboard.readImage();
  }

 static writeImg(Uint8List u8l){
    Clipboard.writeImg(u8l);
  }

  void onShow() async {
    try{
     String? res = await Clipboard.read();
     if(res != null){
       type = ClipboardDataType.text;
       text = res;
     }
     img = (await Clipboard.readImage())!;
     if(img != null){
       type = ClipboardDataType.image;
     }
    }catch(e){
      if (kDebugMode) {
        print(e);
      }
      type = ClipboardDataType.nil;
    }
    notifyListeners();
  }
}